package com.sample.config;

import java.util.Map;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.swak.rabbit.EventBus;
import com.swak.rabbit.RabbitMQTemplate;
import com.swak.rabbit.RabbitMqInitialize;
import com.swak.utils.Maps;

/**
 * 启动初始化消息队列
 * 
 * @author lifeng
 */
@Configuration
@ConditionalOnClass({ EventBus.class })
public class RabbitmqConfig {

	/**
	 * 定义消息队列的初始化, 以及初始化队列
	 * 
	 * @return
	 */
	@Bean
	public RabbitMqInitialize rabbitMqInitialize() {
		return (template) -> {
			this.buildRetryQueue(template);
			this.buildOneChanceQueue(template);
			this.buildDelayQueue(template);
			return true;
		};
	}

	private void buildRetryQueue(RabbitMQTemplate template) {
		Map<String, Object> agruments = Maps.newHashMap();
		agruments.put(com.swak.rabbit.Constants.x_dead_letter_exchange,
				template.applyModule(com.swak.rabbit.Constants.dead_channel));
		agruments.put(com.swak.rabbit.Constants.x_dead_letter_routing_key,
				template.applyModule(com.swak.rabbit.Constants.dead_channel));
		template.exchangeDirectBindQueue("Order_queue", agruments);
		template.exchangeDirectBindQueue("Goods_queue", agruments);
		template.exchangeDirectBindQueue("User_queue", agruments);
	}

	private void buildOneChanceQueue(RabbitMQTemplate template) {

	}

	private void buildDelayQueue(RabbitMQTemplate template) {

	}
}